package com.xhui.vimarket.zkplus.zul.attr.mod.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.directwebremoting.util.Logger;
import org.seasar.framework.util.ClassUtil;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zk.ui.util.Composer;
import org.zkoss.zul.Button;
import org.zkoss.zul.Checkbox;
import org.zkoss.zul.Div;
import org.zkoss.zul.Hbox;
import org.zkoss.zul.Label;
import org.zkoss.zul.Span;
import org.zkoss.zul.Textbox;

import com.xhui.crm.common.ResConstants;
import com.xhui.crm.common.exception.RtManagerException;
import com.xhui.crm.common.util.string.StrUtil;
import com.xhui.crm.common.vo.RetVO;com.xhui.vimarket.zkplusui.vimarket.zkplus.ui.id.ZKRebcom.xhui.vimarket.zkplusrt com.xhui.vimarket.zkplus.com.xhui.vimarket.zkplusil;
import com.xhui.vimcom.xhui.vimarket.zkplusil.NumUtils;
import comcom.xhui.vimarket.zkpluszkplus.util.ZkUiUtil;
impocom.xhui.vimarket.zkplusarket.zkplus.zul.attr.AttrExt;
import com.xhcom.xhui.vimarket.zkpluslus.zul.attr.ada.AttrButtonTextBtnIntf;
impocom.xhui.vimarket.zkplusarket.zkplus.zul.attr.ada.AttrButtonTextTextInf;
imcom.xhui.vimarket.zkplusimarket.zkplus.zul.attr.ada.Refrecom.xhui.vimarket.zkplustBtnIntf;
import com.xhui.vimarkcom.xhui.vimarket.zkplusttr.bean.AttrInst;
import com.xhui.vimarcom.xhui.vimarket.zkplusattr.bean.AttrTmpl;
import comcom.xhui.vimarket.zkpluszkplus.zul.attr.bean.ButtonTextDataVo;
imcom.xhui.vimarket.zkplusimarket.zkplus.zul.attr.bean.ValiVo;
import com.com.xhui.vimarket.zkpluskplus.zul.attr.bean.impl.AttrTmplImpl;
icom.xhui.vimarket.zkplusvimarket.zkplus.zul.attr.evt.AttrButtonTextBtnComposer;
import com.xhcom.xhui.vimarket.zkpluslus.zul.attr.mod.AttrCompConstants;
import com.xhui.vimarket.zkplus.zul.attr.mod.AttrCompUtil;

/**
 * @版权：福富软件 版权所有 (c) 2010
 * @文件：com.xhui.vimarket.zkplus.zul.attr.mod.impl.AttrTextComp.java
 * @所含类：
 * @author: wuyx
 * @version: V1.0
 * @see:
 * @创建日期：2010-12-20
 * @功能说明：属性控件接口
 * @修改记录： =============================================================<br>
 *        日期:2010-12-20 创建
 *        =============================================================<br>
 */
public class AttrBcom.xhui.vimarket.zkplusxtends AttrBaseComp {
    
    /**
     * REFESH_BTN_COMPOSER.
     */
    protected static final String            REFESH_BTN_COMPOSER    = "com.xhui.vimarket.zkcom.xhui.vimarket.zkplusvt.AttrButtonTextRefreshBtnComposer";
    
    /**
     * TXT_COMPOSER.
     */
    protected static final String            TXT_COMPOSER           = "com.xhui.vimarket.zkplus.zul.attr.evt.AttrButtonTextTxtComposer";
    
    /**
     * BTN_DEF_COMPOSER.
     */
    public static final String               BTN_DEF_COMPOSER       = "com.xhui.crm2.common.ui.wind.evt.BaseAttrBtextBtnComposer";
    
    /**
     * BTN_DEF_RTIME_COMPOSER.
     */
    public static final String               BTN_DEF_RTIME_COMPOSER = "com.xhui.crm2.common.ui.wind.evt.rtime.BaseRtimeAttrBtextBtnComposer";
    
    /**
     * BTN_USIM_COMPOSER.
     */
    public static final String               BTN_USIM_COMPOSER      = "com.xhui.crm2.order.ui.sale.attrcomp.UsimCardOccupyComposer";
    
    /**
     * 右边按钮，左边文本模式.
     */
    public static final String               STYLE_BTNTEXT          = "buttontext";
    
    /**
     * 右边label，左边文本和按钮模式.
     */
    public static final String               STYLE_TEXTIMG          = "textimg";
    
    /**
     * 右边label，左边文本和按钮模式，浮动位置在中央.
     */
    public static final String               STYLE_TEXTIMG_CEN      = "textimg_center";
    /**
     * 右边label，左边文本和pop按钮模式.
     */
    public static final String               STYLE_TEXTPOP          = "textimgpop";
    /**
     * 右边label，左边文本和pop按钮模式，浮动位置在中央.
     */
    public static final String               STYLE_TEXTPOP_CEN      = "textimgpop_center";
    
    /**
     * 实例.
     */
    private static AttrButtonTextComp        inst                   = new AttrButtonTextComp();
    
    /**
     * valueId.
     */
    public static final String               TAG_VALUE_ID           = "valueId";
    
    /**
     * TAG_VALUE_OBJECT.
     */
    public static final String               TAG_VALUE_OBJECT       = "valueObj";
    
    /**
     * 日志.
     */
    private static Logger                    logger                 = Logger
                                                                        .getLogger(AttrButtonTextComp.class);
    /**
     * 主数据参数2.
     */
    private String                           param2url              = null;
    
    private static AttrButtonTextBtnComposer baseBtnComposer        = (AttrButtonTextBtnComposer) ClassUtil
                                                                        .newInstance(AttrButtonTextComp.BTN_DEF_COMPOSER);
    
    private static AttrButtonTextBtnComposer baseRtimeBtnComposer   = (AttrButtonTextBtnComposer) ClassUtil
                                                                        .newInstance(AttrButtonTextComp.BTN_DEF_RTIME_COMPOSER);
    
    /**
     * 构造函数. 
     */
    protected AttrButtonTextComp() {
    }
    
    /**
     * 获取实例.
     * 
     * @return AttrBaseComp
     */
    public static AttrButtonTextComp instance() {
        return AttrButtonTextComp.inst;
    }
    
    /**
     * 生成组件.
     * 
     * @param attrExt 组件控件
     * @param attrTmpl 组件模板
     * @param comp 显示容器组件
     */
    @SuppressWarnings("deprecation")
    @Override
    public void create(final AttrExt attrExt, final AttrTmpl attrTmpl, final Component comp) {
        super.create(attrExt, attrTmpl, comp);
        
        // hbox
        final Hbox hbox = new Hbox();
        
        //url地址格式为relaType=61&otherType=62  （relaType计费号码）黄元强 2011-11-25
        String url = null;
        if (attrTmpl.getParam2() != null) {
            if (attrTmpl.getParam2().contains("?")) {
                int index = attrTmpl.getParam2().indexOf("?");
                if (index != -1) {
                    url = attrTmpl.getParam2().substring((int) (index) + 1);
                    param2url = attrTmpl.getParam2().substring(0, index);
                }
            } else {
                param2url = attrTmpl.getParam2();
            }
        } else {
            param2url = null;
        }
        hbox.setAttribute(AttrBaseComp.COMP_ARG, url);
        hbox.setSclass("zh-hbox-widths");
        hbox.setAttribute(AttrBaseComp.COMP_MODE, attrTmpl.getDisplayMode());
        hbox.setAttribute(AttrBaseComp.COMP_STYLE, attrTmpl.getDisplayStyle());
        hbox.setAttribute(AttrBaseComp.COMP_ATTRID, attrTmpl.getAttrId());
        hbox.setAttribute(AttrBaseComp.COMP_JAVACODE, attrTmpl.getJavaCode());
        hbox.setAttribute(AttrBaseComp.COMP_PARAM1, attrTmpl.getParam1());
        hbox.setAttribute(AttrBaseComp.COMP_PARAM2, param2url);
        hbox.setAttribute(AttrBaseComp.COMP_CANTNULL, AttrCompUtil.getStrCantNull(attrTmpl
            .isCantNull()));
        hbox.setAttribute(AttrBaseComp.COMP_COMP_NAME, attrTmpl.getName());
        AttrCompUtil.setCompAttr(hbox, AttrBaseComp.COMP_VALUE_LENGTH, attrTmpl.getValueLength());
        AttrCompUtil.setCompAttr(hbox, AttrBaseComp.COMP_VALUE_FROM, attrTmpl.getValueFrom());
        AttrCompUtil.setCompAttr(hbox, AttrBaseComp.COMP_VALUE_TO, attrTmpl.getValueTo());
        AttrCompUtil.setCompAttr(hbox, AttrBaseComp.COMP_VALUE_REX, attrTmpl.getValidExpr());
        hbox.setWidth("100%");
        hbox.setWidths(this.getWidthsLCT(attrTmpl));
        hbox.setAttribute("WTS", this.getWidthsLCTS(attrTmpl));
        if (attrTmpl.getHint() != null) {
            hbox.setTooltiptext(attrTmpl.getHint());
        }
        
        final Div div = new Div();
        // add to zul
        hbox.setParent(comp);
        div.setParent(hbox);
        div.setAlign("right");
        Span span = new Span();
        span.setWidth("1px");
        span.setParent(div);
        // Executions.createComponentsDirectly("<span width=\"1px\" />", null, div, null); // popup parent
        //        final String sButtonWithComposer = attrExt.getAttrAda().getAttrTmplCompStr(
        //            attrTmpl.getDisplayMode(), attrTmpl, attrTmpl.getParam2(), null, null);
        //        final Button button = (Button) Executions.createComponentsDirectly(sButtonWithComposer,
        //            null, div, null);
        
        final Button button = (Button) attrExt.getAttrAda().getAttrTmplCompStr(
            attrTmpl.getDisplayMode(), attrTmpl, param2url, null, null, div);
        button.setLabel(attrTmpl.getName());
        button.setSclass("zp-abtn");
        if (attrTmpl.isReadOnly()) {
            button.setDisabled(true);
        }
        // button.setAutodisable("self"); 加上有问题，浮动问题
        Span span2 = new Span();
        span2.setWidth("5px");
        span2.setParent(div);
        // Executions.createComponentsDirectly("<span width=\"5px\" />", null, div, null);
        
        // info
        final Span infDiv = this.createRulebar(attrExt, div, attrTmpl);
        final Label label = new Label(attrTmpl.getName());
        label.setParent(div);
        label.setSclass("zp-lt-label");
        /*final Button refreshbutton = (Button) Executions.createComponentsDirectly(
            "<button apply=\"" + AttrButtonTextComp.REFESH_BTN_COMPOSER + "\" />", null, div, null);
        refreshbutton.setLabel("x");*/
        final Div divt = new Div();
        divt.setParent(hbox);
        final Textbox textbox = new Textbox();
        ComposerUtil.bindComposer(textbox, AttrButtonTextComp.TXT_COMPOSER, divt);
        //        final Textbox textbox = (Textbox) Executions.createComponentsDirectly("<textbox apply=\""
        //            + AttrButtonTextComp.TXT_COMPOSER + "\" />", null, divt, null);
        textbox.setWidth(AttrBaseComp.WIDTH_BTNTEXT);
        //textbox.setStyle("_display:block;");
        //if (attrTmpl.isReadOnly()) {
        textbox.setReadonly(true);
        //}
        if (AttrButtonTextComp.BTN_USIM_COMPOSER.equals(param2url)) {
            textbox.setReadonly(false);
            
        }
        
        ZKRebuildUuid.rebuildUuidById(textbox, "textbox_"
            + (attrTmpl.getAttrId() > 0 ? attrTmpl.getAttrId()
                : "_" + Math.abs(attrTmpl.getAttrId())));
        //        final Button btnimg = (Button) Executions.createComponentsDirectly(sButtonWithComposer,
        //            null, divt, null);
        final Button btnimg = (Button) attrExt.getAttrAda().getAttrTmplCompStr(
            attrTmpl.getDisplayMode(), attrTmpl, param2url, null, null, divt);
        // btnimg.setAutodisable("self"); 加上有问题，浮动问题
        // btnimg.setLabel("@");        
        btnimg.setImage(ResConstants.IMG_FIND);        
        btnimg.setClass("z-button-text-btn");
        if (attrTmpl.isReadOnly()) {
            btnimg.setDisabled(true);
        }
        
        btnimg.setAttribute(AttrButtonTextComp.STYLE_TEXTIMG, 1);
        //重构Uuid用于压力测试。
        ZKRebuildUuid.rebuildUuidById(btnimg, "abtc_"
            + (attrTmpl.getAttrId() > 0 ? attrTmpl.getAttrId()
                : "_" + Math.abs(attrTmpl.getAttrId())));
        Span span3 = new Span();
        span3.setWidth("5px");
        span3.setParent(divt);
        // Executions.createComponentsDirectly("<span width=\"5px\" />", null, divt, null); // popup parent2
        Button button2 = new Button();
        ComposerUtil.bindComposer(button2, AttrButtonTextComp.REFESH_BTN_COMPOSER, divt);
        button2.setLabel("X");
        //        Executions.createComponentsDirectly("<button apply=\""
        //            + AttrButtonTextComp.REFESH_BTN_COMPOSER + "\" label=\"X\" />", null, divt, null);
        
        final Div bDiv = new Div();
        //2011-12-27 chenmh ttp4481 自助（预约）选号占用，默认隐藏
        Hbox hb = new Hbox();
        Button occupyBtn = new Button();
        occupyBtn.setLabel("占用");
        occupyBtn.setWidth("50px");
        occupyBtn.setParent(hb);
        occupyBtn.setVisible(false);
        //2011-12-13 linzhiqiang ttp5879 扩展自动选号按钮，默认隐藏
        bDiv.setParent(hbox);
        Button autoBtn = new Button();
        autoBtn.setLabel("自动选号");
        autoBtn.setWidth("80px");
        autoBtn.setStyle("margin-left:3px;");
        autoBtn.setParent(hb);
        //autoBtn.setImage(ResConstants.IMG_FIND);
        //autoBtn.setStyle("width:28px;height:21px;");
        autoBtn.setVisible(false);
        
        //add by luxb 2012-2-1 已拆号码
        Button oldSoBtn = new Button();
        oldSoBtn.setLabel("已拆号码");
        oldSoBtn.setWidth("75px");
        oldSoBtn.setParent(hb);
        oldSoBtn.setStyle("margin-left:3px;");
        oldSoBtn.setVisible(false);
        
        Button writeCardBtn = new Button();
        writeCardBtn.setLabel("写卡");
        writeCardBtn.setWidth("60px");
        //页面显示正常--黄元强 2012-7-31
        writeCardBtn.setStyle("margin-left:60px;");
        writeCardBtn.setParent(hb);
        writeCardBtn.setVisible(false);
        
        //add by luxb 2012-4-26 号码迁移
        Button moveAccNbrBtn = new Button();
        moveAccNbrBtn.setLabel("号码迁移");
        moveAccNbrBtn.setWidth("75px");
        moveAccNbrBtn.setParent(hb);
        moveAccNbrBtn.setVisible(false);
        
        //add by chenmh 2012-4-28 生成现金账户
        Checkbox newCashCheckbox = new Checkbox();
        newCashCheckbox.setLabel("新增账户");
        newCashCheckbox.setParent(hb);
        newCashCheckbox.setVisible(false);
        newCashCheckbox.setStyle("width:72px;display:block;");
        
        //add by zhenggw 2012-8-13 清空发展员工
        Button clearBtn = new Button();
        clearBtn.setLabel("清空");
        clearBtn.setWidth("50px");
        clearBtn.setParent(hb);
        clearBtn.setVisible(false);
        
        hb.setParent(bDiv);
        
        // comp log
        if (AttrButtonTextComp.logger.isDebugEnabled()) {
            attrExt.appendInnerComp("<hbox width=\"100%\" widths=\"40%,60%\" >");
            attrExt.appendInnerCompAttr(AttrBaseComp.COMP_MODE, attrTmpl.getDisplayMode());
            attrExt.appendInnerCompAttr(AttrBaseComp.COMP_ATTRID, "" + attrTmpl.getAttrId());
            attrExt.appendInnerCompAttr(AttrBaseComp.COMP_JAVACODE, "" + attrTmpl.getJavaCode());
            attrExt.appendInnerComp("<button label=\"");
            attrExt.appendInnerComp(attrTmpl.getName());
            attrExt.appendInnerComp("\" />");
            attrExt.appendInnerComp("<textbox ");
            if (attrTmpl.isReadOnly()) {
                attrExt.appendInnerComp("readonly=\"true\"");
            }
            attrExt.appendInnerComp("/>");
            attrExt.appendInnerComp("</hbox>");
        }
        // toolbox
        this.createToolbox(hbox, attrExt.isToolboxVisible(), attrTmpl);
        
        // 模式选择
        if (attrExt.getAttrAda().isViewMode()) { // 展示模式
            label.setVisible(true);
            btnimg.setVisible(false);
            button.setVisible(false);
            writeCardBtn.setAttribute("viewMode", attrExt.getAttrAda().isViewMode() + "");
        } else if (AttrButtonTextComp.STYLE_BTNTEXT.equals(attrTmpl.getDisplayStyle() + "")) {
            label.setVisible(false);
            btnimg.setVisible(false);
            textbox.addForward(Events.ON_OK, button, Events.ON_CLICK);
            button.setAutodisable("self"); // 只能为非popup的时候自动隐藏，否则popup会因为焦点的变化而闪动
            btnimg.setAutodisable("self"); // 只能为非popup的时候自动隐藏，否则popup会因为焦点的变化而闪动
        } else {
            button.setVisible(false);
            textbox.addForward(Events.ON_OK, btnimg, Events.ON_CLICK);
            if (AttrButtonTextComp.STYLE_TEXTIMG.equals(attrTmpl.getDisplayStyle() + "")) {
                button.setAutodisable("self"); // 只能为非popup的时候自动隐藏，否则popup会因为焦点的变化而闪动
                btnimg.setAutodisable("self"); // 只能为非popup的时候自动隐藏，否则popup会因为焦点的变化而闪动
            }
        }
        
        super.afterCreate(attrExt, attrTmpl, comp);
    }
    
    public static void redrawWidth(final Component comp) {
        Hbox hbox = (Hbox) comp;
        Object wts = hbox.getAttribute("WTS");
        if (wts != null) {
            hbox.setWidths(wts + "");
        }
    }
    
    /**
     * 设置值.
     * 
     * @param attrExt 组件控件
     * @param comp 组件
     * @param attrInstList 属性实例
     */
    @Override
    public void setValue(final AttrExt attrExt, final Component comp,
        final List<AttrInst> attrInstList, Map<String, Integer> attrViewMap) {
        super.setValue(attrExt, comp, attrInstList, attrViewMap);
        // 取composer,进行初始化
        Composer composer = ComposerUtil.getComposer(AttrButtonTextComp.getButton(comp));
        if (composer != null && composer instanceof AttrButtonTextBtnIntf) {
            ((AttrButtonTextBtnIntf) composer).initVal();
        }
        
        // 取输入框
        final Component compTextbox = getTextbox(comp);
        if (compTextbox != null) { // 如果设置为控制独立采集，无需进行设置
            final long theAttrId = NumUtils
                .toLong("" + comp.getAttribute(AttrBaseComp.COMP_ATTRID));
            if (theAttrId == 0) {
                return; // 无规格无需设置值
            }
            final ArrayList<AttrInst> theAttrList = AttrBaseComp.getAttrInstListById(attrInstList,
                theAttrId);
            if (theAttrList.size() > 0) {
                if (!compTextbox.hasAttribute(AttrButtonTextComp.TAG_VALUE_ID)) {
                    compTextbox.setAttribute(AttrButtonTextComp.TAG_VALUE_ID, theAttrList.get(0)
                        .getParam1());
                    ((Textbox) compTextbox).setValue(theAttrList.get(0).getParam2() == null ? ""
                        : theAttrList.get(0).getParam2());
                    
                    // javacode回填
                    AttrCompUtil.copyTmplInfo(theAttrList.get(0), comp);
                    setAttrView(comp, attrViewMap);
                }
            }
        }
    }
    
    /**
     * 获取值.
     * 
     * @param attrExt 组件控件
     * @param comp 组件
     * @return ArrayList<AttrInst>
     */
    @Override
    public ArrayList<AttrInst> getValue(final AttrExt attrExt, final Component comp) {
        super.getValue(attrExt, comp);
        final ArrayList<AttrInst> retList = new ArrayList<AttrInst>();
        // 取输入框
        final Component compTextbox = getTextbox(comp);
        if (compTextbox != null) {
            final Object oValueId = compTextbox.getAttribute(AttrButtonTextComp.TAG_VALUE_ID);
            if (oValueId != null && !StrUtil.isNullOrEmpty(oValueId + "")) { // 有填， 并且控件没有设置为不允许统一采集
                final long attrId = NumUtils.toLong(""
                    + comp.getAttribute(AttrBaseComp.COMP_ATTRID));
                if (attrId == 0) {
                    return retList;
                }
                final Object oJavaCode = comp.getAttribute(AttrBaseComp.COMP_JAVACODE);
                final Object oParam2 = comp.getAttribute(AttrButtonTextComp.COMP_PARAM2);
                final AttrInst attrInst = attrExt.newAttrInst();
                attrInst.setAttrId(attrId);
                attrInst.setJavaCode(oJavaCode == null ? ""
                    : "" + oJavaCode);
                attrInst.setParam1(oValueId == null ? null
                    : "" + oValueId);
                attrInst.setTmplParam2(oParam2 == null ? null
                    : "" + oParam2);
                attrInst.setTmplDisplayMode(AttrTmplImpl.MODE_BUTTONTEXT);
                attrInst.com.xhui.vimarket.zkplusoolbarOp(comp));
                retList.addcom.xhui.vimarket.zkplus          }
        }
        return retList;
    }
    
    /**
     * {@inheritDoc}
     * @see com.xhui.vimarket.zkplus.zul.attr.mod.impl.AttrBaseComp#signRuleHint(com.xhui.vimarket.zkplus.zul.attr.AttrExt, org.zkoss.zk.ui.Component)
     * @author wuyx
     * 2012-2-16 wuyx
     */
    @Override
    public ArrayList<ValiVo> signRuleHint(AttrExt attrExt, Component comp) {
        super.signRuleHint(attrExt, comp);
        if (AttrCompUtil.isCantNull(comp)) { // 必填
            ArrayList<AttrInst> valList = this.getValue(attrExt, comp);
            if (valList == null || valList.size() < 1) {
                ValiVo retVo = new ValiVo();
                ArrayList<ValiVo> retVoList = new ArrayList<ValiVo>();
                retVoList.add(retVo);
                return retVoList;
            }
        }
        return null;
    }
    
    /**
     * 获取值.
     * 
     * @param attrExt 组件控件
     * @param comp 组件
     * @param flag boolean
     * @return ArrayList<AttrInst>
     */
    private ArrayList<AttrInst> getValueWithCheckReget(final AttrExt attrExt, final Component comp,
        boolean flag) {
        super.getValue(attrExt, comp);
        final ArrayList<AttrInst> retList = new ArrayList<AttrInst>();
        // 取输入框
        final Component compTextbox = getTextbox(comp);
        if (compTextbox != null) {
            final Object oValueId = compTextbox.getAttribute(AttrButtonTextComp.TAG_VALUE_ID);
            if (oValueId != null && !StrUtil.isNullOrEmpty(oValueId + "")) { // 有填， 并且控件没有设置为不允许统一采集
                final long attrId = NumUtils.toLong(""
                    + comp.getAttribute(AttrBaseComp.COMP_ATTRID));
                if (attrId == 1) {
                    return retList;
                }
                final Object oJavaCode = comp.getAttribute(AttrBaseComp.COMP_JAVACODE);
                final Object oParam2 = comp.getAttribute(AttrButtonTextComp.COMP_PARAM2);
                final AttrInst attrInst = attrExt.newAttrInst();
                attrInst.setAttrId(attrId);
                attrInst.setJavaCode(oJavaCode == null ? ""
                    : "" + oJavaCode);
                attrInst.setParam1(oValueId == null ? null
                    : "" + oValueId);
                attrInst.setTmplParam2(oParam2 == null ? null
                    : "" + oParam2);
                attrInst.setOp(this.getToolbarOp(comp));
                attrInst.setTmplDisplayMode(AttrTmplImpl.MODE_BUTTONTEXT);
                retList.add(attrInst);
            }
        }
        return retList;
    }
    
    /**
     * 取空值属性实例.
     * 
     * @param attrExt 组件控件
     * @param attrTmpl 模板
     * @return ArrayList<AttrInst>
     */
    @Override
    public ArrayList<AttrInst> getNullValue(final AttrExt attrExt, final AttrTmpl attrTmpl) {
        super.getNullValue(attrExt, attrTmpl);
        final ArrayList<AttrInst> retList = new ArrayList<AttrInst>();
        if (attrTmpl.getAttrId() < 1) {
            return retList; // 无需
        }
        final AttrInst attrInst = attrExt.newAttrInst();
        attrInst.setAttrId(attrTmpl.getAttrId());
        attrInst.setJavaCode(attrTmpl.getJavaCode());
        attrInst.setTmplParam2(param2url);
        attrInst.setTmplDisplayMode(attrTmpl.getDisplayMode());
        retList.add(attrInst);
        return retList;
    }
    
    /**
     * 清空值.
     * 
     * @param attrExt 组件控件
     * @param comp 组件
     */
    @Override
    public void clean(final AttrExt attrExt, final Component comp) {
        super.clean(attrExt, comp);
        // 取输入框
        final Component compTextbox = getTextbox(comp);
        if (compTextbox != null) {
            ((Textbox) compTextbox).setText("");
        }
    }
    
    /**
     * getTextbox.
     * 
     * @param root Component
     * @return Textbox
     */
    public static Textbox getTextbox(Component root) {
        // 取输入框
        // hbox // div(1) // textbox(0)
        Textbox tb = null;
        if (root.getFirstChild().getNextSibling() != null) {
            tb = (Textbox) root.getFirstChild().getNextSibling().getFirstChild();
        }
        return tb;
    }
    
    /**
     * getButton.
     * 
     * @param root Component
     * @return Button
     */
    public static Button getButton(Component root) {
        // 取按钮
        // hbox // div(0) // button(1)
        return (Button) root.getFirstChild().getFirstChild().getNextSibling();
    }
    
    /**
     * getButton.
     * 
     * @param root Component
     * @return Button
     */
    public static Button getImgbtn(Component root) {
        // 取按钮
        // hbox // div(0) // button(1)
        return (Button) getTextbox(root).getNextSibling();
    }
    
    /**
     * setImgbtnOk.
     * 
     * @param root Component
     * @author wuyx
     * 2011-5-7 wuyx 
     */
    public static void setImgbtnOk(Component root) {
        getImgbtn(root).setImage(ResConstants.IMG_ACCECP);
    }
    
    /**
     * setImgbtnInit.
     * 
     * @param root Component
     * @author wuyx
     * 2011-5-7 wuyx 
     */
    public static void setImgbtnInit(Component root) {
        getImgbtn(root).setImage(ResConstants.IMG_FIND);
    }
    
    /**
     * getPopParent.
     * 
     * @param root Component
     * @return Span
     */
    public static Span getPopParent(Component root) {
        // 取按钮
        // hbox // div(0) // Span(0)
        return (Span) root.getFirstChild().getFirstChild();
    }
    
    /**
     * 设置为不允许修改.
     * 
     * @param attrExt 组件控件
     * @param comp 组件
     * @param tflag 设置值，true/false
     */
    @Override
    public void setDisabled(Attcom.xhui.vimarket.zkplusomponent comp, boolean tflag) {
        super.setcom.xhui.vimarket.zkplust, comp, tflag);
        ZkUiUtil.setDisabled(comp, tflag);
    }
    
    /**
     * {@inheritDoc}
     * @see com.xhui.vimarket.zkplus.zul.attr.mod.impl.AttrBaseComp
     * #validate(com.xhui.vimarket.zkplus.zul.attr.AttrExt, org.zkoss.zk.ui.Component)
     * @author wuyx
     * 2011-3-23 wuyx
     */
    @Override
    public List<RetVO> validate(AttrExt attrExt, Component comp) {
        if (AttrCompUtil.isCantNull(comp)) { // 需限制不可空
            ArrayList<AttrInst> valList = this.getValueWithCheckReget(attrExt, comp, true);
            if (valList == null || valList.size() < 1) { // 没有值
                return AttrCompUtil.getRetVoList(AttrCompConstants.RET_ERROR, AttrCompUtil
                    .getCompNamecom.xhui.vimarket.zkplus             + AttrCompConstants.STRING_CANT_NULL, comp);
com.xhui.vimarket.zkplus            return null; // 通过
        }
        return null; // 通过
    }
    
    /**
     * {@inheritDoc}
     * @see com.xhui.vimarket.zkplus.zul.attr.mod.impl.AttrBaseComp
     * #refreshButtonText(com.xhui.vimarket.zkplus.zul.attr.AttrExt, org.zkoss.zk.ui.Component)
     * @author wuyx
     * 2011-3-24 wuyx
     */
    @Override
    public void refreshButtonText(AttrExt attrExt, Component comp, final List<AttrInst> attrInstList) {
        if (comp != null) {
            Button btn = AttrButtonTextComp.getButton(comp);
            Textbox textbox = AttrButtonTextComp.getTextbox(comp);
            if (btn != null && textbox != null) {
                AttrButtonTextBtnIntf btnComposer = (AttrButtonTextBtnIntf) ComposerUtil
                    .getComposer(btn);
                AttrButtonTextTextInf textComposer = (AttrButtonTextTextInf) ComposerUtil
                    .getComposer(textbox);
                if (btnComposer != null) {
                    btnComposer.initVal();
                }
                if (textComposer != null) {
                    textComposer.initVal(textbox);
                }
                if (btnComposer != null
                    && !(ClassUtil.isAssignableFrom(AttrButtonTextComp.baseBtnComposer.getClass(),
                        btnComposer.getClass()) || ClassUtil
                        .isAssignableFrom(
                            AttrButtonTextComp.baseRtimeBtnComposer.getClass(),btnComposer.getClass()))
                    && attrInstList != null && attrInstList.size() > 0) {
                    ButtonTextDataVo vo = new ButtonTextDataVo();
                    vo.setValueId(attrInstList.get(0).getParam1());
                    vo.setValueName(attrInstList.get(0).getParam1());
                    vo.setValueLabel(attrInstList.get(0).getParam1());
                    btnComposer.doShowReturnData(vo);
                }
                else if (btnComposer != null && btnComposer instanceof RefreshAttrButtonTextBtnIntf
                    && attrInstList != null && attrInstList.size() > 0) {
                    if(((RefreshAttrButtonTextBtnIntf)btnComposer).getRefreshFlag()){
                        ButtonTextDataVo vo = new ButtonTextDataVo();
                        vo.setValueId(attrInstList.get(0).getParam1());
                        vo.setValueName(attrInstList.get(0).getParam1());
                        vo.setValueLabel(attrInstList.get(0).getParam1());
                        btnComposer.doShowReturnData(vo);
                    }
                }
            }
        }
    }
    
    /**
     * fillValue.
     * 
     * @param rootComp Component
     * @param valueId Object
     * @param valueName String
     * @param valueObject Object 
     * @author wuyx
     * 2011-4-1 wuyx 
     */
    public static void fillValue(Component rootComp, Object valueId, String valueName,
        Object valueObject) {
        Textbox textbox = AttrButtonTextComp.getTextbox(rootComp);
        if (rootComp == null || textbox == null) {
            throw new RtManagerException("设置值@valueName错误，无法找到控件", AttrButtonTextComp.class,
                "fillValue", "rootCompNull", "valueName", valueName);
        }
        textbox.setAttribute(AttrButtonTextComp.TAG_VALUE_ID, valueId);
        if (valueObject != null) {
            textbox.setAttribute(AttrButtonTextComp.TAG_VALUE_OBJECT, valueObject);
        }
        textbox.setValue(valueName);
    }
    
    /**
     * fillReturnData.
     * 
     * @param rootComp Component
     * @param btdv ButtonTextDataVo
     */
    public static void fillReturnData(Component rootComp, final ButtonTextDataVo btdv) {
        final Textbox textbox = AttrButtonTextComp.getTextbox(rootComp);
        if (btdv.isReset()) { // 清空
            textbox.setValue("");
            textbox.removeAttribute(AttrButtonTextComp.TAG_VALUE_ID);
            textbox.removeAttribute(AttrButtonTextComp.TAG_VALUE_OBJECT);
        } else { // 设置
            textbox.setValue(btdv.getValueLabel() == null ? btdv.getValueName()
                : btdv.getValueLabel());
            textbox.setcom.xhui.vimarket.zkplusuttonTextComp.TAG_VALUE_ID, btdv.getValueId());
            textbox.setAttribute(AttrButtonTextComp.TAG_VALUE_OBJECT, btdv.getData());
        }
    }
    
    @Override
    /**
     * {@inheritDoc}
     * @see com.xhui.vimarket.zkplus.zul.attr.mod.AttrComp
     * #setAttrView(org.zkoss.zk.ui.Component, Map<String, Integer>)
     * @author chenmh
     * 2011-6-16 chenmh
     */
    public void setAttrView(final Component comp, Map<String, Integer> attrViewMap) {
        if (attrViewMap != null && attrViewMap.size() > 0) {
            String attrJC = comp.getAttribute(AttrBaseComp.COMP_JAVACODE) + "";
            if (!StrUtil.isNullOrEmpty(attrJC)) {
                Integer viewType = attrViewMap.get(attrJC);
                // 取输入框
                final Textbox textbox = getTextbox(comp);
                if (textbox != null) {
                    textbox.setVisible(false);
                    if (AttrBaseComp.VIEW_TYPE_SHOW.equals(viewType)) {
                        textbox.setDisabled(true);
                        textbox.setVisible(true);
                        //textbox.setValue("@@@@@@");
                    } else if (AttrBaseComp.VIEW_TYPE_EDIT.equals(viewType)) {
                        textbox.setVisible(true);
                    } else if (AttrBaseComp.VIEW_TYPE_NONE.equals(viewType)) {
                        textbox.setVisible(true);
                        textbox.setValue(AttrBaseComp.VIEW_NONE);
                    }
                }
            }
        }
    }
    
    @Override
    public void setAttrConstrain(Component comp, Map<Object, String> attrConstrainMap) {
        // TODO Auto-generated method stub
        if (attrConstrainMap != null && attrConstrainMap.size() > 0) {
            String attrJC = comp.getAttribute(AttrBaseComp.COMP_JAVACODE) + "";
            String val = attrConstrainMap.get(attrJC);
            if (val != null && val.indexOf(AttrBaseComp.CNS_TYPE_EXTRA_NCP + ";") != -1) {
                final Textbox textbox = getTextbox(comp);
                ZkUiUtil.setCompDisableCopy(textbox, "对不起，您没有拷贝的权限！",
                    ZkUiUtil.DISPLAY_COPY_CONTEXT_MOLD_MENU);
            }
        }
    }
    
    /**
     * 
     * 方法功能:
     *  获取自助（预约）选号占用按钮.
     * @param root
     * @return
     * @author: chenmh
     * @修改记录： 
     * ==============================================================<br>
     * 日期:2011-12-27 chenmh 创建方法，并实现其功能
     * ==============================================================<br>
     */
    public static Button getOccupyBtn(Component root) {
        AttrButtonTextComp.redrawWidth(root);
        return (Button) root.getFirstChild().getNextSibling().getNextSibling().getFirstChild()
            .getChildren().get(0);
    }
    
    /**
     * 
     * 方法功能:
     *  获取自动选号按钮.
     * @param root
     * @return
     * @author: linzhiqiang
     * @修改记录： 
     * ==============================================================<br>
     * 日期:2011-12-13 linzhiqiang 创建方法，并实现其功能
     * ==============================================================<br>
     */
    public static Button getAutoNbrBtn(Component root) {
        AttrButtonTextComp.redrawWidth(root);
        return (Button) root.getFirstChild().getNextSibling().getNextSibling().getFirstChild()
            .getChildren().get(1);
    }
    
    /**
     * 获取已拆号码按钮.
     * @param root 组件
     * @return 按钮
     * @author luxb
     *         2012-2-9 luxb
     */
    public static Button getOldNbrBtn(Component root) {
        AttrButtonTextComp.redrawWidth(root);
        return (Button) root.getFirstChild().getNextSibling().getNextSibling().getFirstChild()
            .getChildren().get(2);
        
    }
    
    /**
     * 
     * 方法功能:
     *  获取白卡写卡按钮.
     * @param root
     * @return
     * @author: liuyq
     * @修改记录： 
     * ==============================================================<br>
     * 日期:2011-12-13 liuyq 创建方法，并实现其功能
     * ==============================================================<br>
     */
    public static Button getWriteCardBtn(Component root) {
        AttrButtonTextComp.redrawWidth(root);
        return (Button) root.getFirstChild().getNextSibling().getNextSibling().getFirstChild()
            .getChildren().get(3);
    }
    
    /**
     * 
     * 获取号码迁移按钮.
     * @param root 控件
     * @return 按钮
     * @author luxb
     * 		   2012-4-26 luxb
     */
    public static Button getMoveAccNbrBtn(Component root) {
        AttrButtonTextComp.redrawWidth(root);
        return (Button) root.getFirstChild().getNextSibling().getNextSibling().getFirstChild()
            .getChildren().get(4);
    }
    
    /**
     * 
     * 获取新增现金默认账户Checkbox.
     * @param root 控件
     * @return Checkbox
     * @author 陈明辉
     *         2012-4-28 陈明辉
     */
    public static Checkbox getNewCashCheckbox(Component root) {
        AttrButtonTextComp.redrawWidth(root);
        return (Checkbox) root.getFirstChild().getNextSibling().getNextSibling().getFirstChild()
            .getChildren().get(5);
    }

    /**
     * 发展员工清空按钮
     * .
     * 
     * @return
     * @author zhenggw
     * 2012-8-13 zhenggw
     */
    public static Button getClearBtn(Component root) {
        AttrButtonTextComp.redrawWidth(root);
        return (Button) root.getFirstChild().getNextSibling().getNextSibling().getFirstChild()
            .getChildren().get(6);
    }
}
